<template>
	<el-button type="primary" v-bind="$attrs" @click="downAuxiliary">下载辅助数据</el-button>
</template>
<script>
export default {
	name: "auxiliary-data-btn",
	props: {
		api: {
			type: String,
			require: true
		}
	},
	data() {},
	methods: {
		// 下载辅助数据
		downAuxiliary() {
			this.$crud.openForm({
				title: "下载辅助数据",
				width: "400px",
				props: {
					"label-position": "top"
				},
				items: [
					{
						label: "事业部",
						prop: "biz_id",
						value: this.getCurrBiz(),
						component: {
							name: "el-select",
							attrs: {
								placeholder: "请选择事业部"
							},
							options: this.business
						},
						rules: {
							required: true,
							message: "请选择事业部"
						}
					}
				],
				op: {
					saveButtonText: "确定"
				},
				on: {
					submit: async (data, { close, done }) => {
						try {
							const res = await this.$service.duxiliaryDataDownload[this.api](data);
							window.open(res, "__blank");
							close();
						} catch (error) {
							done();
						}
					}
				}
			});
		}
	}
};
</script>
